<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue-computed属性使用</title>
</head>

<body>
    <div id="app">
        <div>{{judge()}}</div>
        <div>{{judge()}}</div>
        <div>{{pan}}</div>
        <div>{{pan}}</div>
        <h2>所有成绩</h2>
        <ul>
            <li v-for:="item in grades">{{item}}</li>
        </ul>
        <h2>及格成绩</h2>
        <ul>
            <li v-for:="item in pass2">{{item}}</li>
        </ul>
        <ul>
            <template v-for:="item in grades">
                <li v-if="pass(item)">{{item}}</li>
            </template>
        </ul>
    </div>
    <script src="./vue.global.js"></script>
    <script>
        const { createApp } = Vue;
        createApp({
            data() {
                return {
                    author: {
                        name: "zhangsan",
                        books: ["vue1", "vue1", "vue1"]
                    },
                    grades: [96, 77, 56, 34, 78, 26, 88, 66, 82]
                }
            },
            methods: {
                judge() {
                    console.log(1);
                    return this.author.books.length > 0 ? "有著作" : "无著作";
                }
            },
            computed: {
                pan() {
                    console.log(2);
                    return this.author.books.length > 0 ? "有著作" : "无著作";
                },
                pass() {
                    return (i) => i>=60?true:false;
                },
                pass2() {
                    let arr = this.grades.filter((e) => e >= 60);
                    return arr;
                }
            }
        }).mount('#app');
    </script>
</body>

</html>